<!DOCTYPE html>
<html lang="en"  xmlns:th="http://www.thymeleaf.org">
    <head>
        <meta charset="UTF-8">
        <title>菜单管理</title>
        <link rel="stylesheet" href="../../component/pear/css/pear.css"/>
    </head>
    <body>
        <form class="layui-form" action="">
            <div class="mainBox">
                <div class="main-container">
                    <div class="main-container">
                        <input type="hidden" name="id" value="${menuInfo.id!}">
                        <input type="hidden" name="createtime" value="${menuInfo.createtime!}">
                        <div class="layui-form-item">
                            <label class="layui-form-label">菜单名称</label>
                            <div class="layui-input-block">
                                <input type="text" name="title" lay-verify="required" value="${menuInfo.title!}" autocomplete="off" placeholder="请输入菜单名称" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">父级菜单</label>
                            <div class="layui-input-block">
                                <select name="parent" lay-verify="required">
                                    <option value="-1" selected>无</option>
                                    @for(item in level1!){
                                    <option value="${item.id}" ${item.isLeaf==1||item.id==(menuInfo.id!)?'disabled':''} ${item.id==(menuInfo.parent!)?'selected':''}>${item.title!}</option>
                                    @}
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">菜单图标</label>
                            <div class="layui-input-block">
                                <input type="text" name="icon" id="iconPicker" value="${menuInfo.icon!'layui-icon-set'}" lay-filter="iconPicker" class="hide">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">排序</label>
                            <div class="layui-input-block">
                                <input type="number"  name="sort" lay-verify="number" required autocomplete="off" value="${menuInfo.sort!1}" placeholder="请输入菜单序号" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">链接</label>
                            <div class="layui-input-block">
                                <input type="text"  name="href" lay-verify="title" autocomplete="off" value="${menuInfo.href!}" placeholder="请输入链接地址" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">状态</label>
                            <div class="layui-input-block">
                                <input type="checkbox" name="state" lay-skin="switch" lay-text="启用|禁用" ${menuInfo.state!1==1?'checked':''}>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="bottom">
                <div class="button-container">
                    <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit="" lay-filter="menu-save">
                        <i class="layui-icon layui-icon-ok"></i>
                        提交
                    </button>
                    <button type="reset" class="pear-btn pear-btn-sm">
                        <i class="layui-icon layui-icon-refresh"></i>
                        重置
                    </button>
                </div>
            </div>
        </form>
        <script src="../../component/layui/layui.js"></script>
        <script src="../../component/pear/pear.js"></script>
        <script>
            layui.use(['form','jquery','icon'],function(){
                let form = layui.form;
                let $ = layui.jquery;
                let icon = layui.icon;

                let MODULE_PATH = "${ctxPath}/menu/";

                icon.render({
                    elem: '#iconPicker'
                    ,style: 'color: #5FB878;'
                    ,placeholder: '请选择图标'
                    ,isSplit: true
                    ,page: true
                    ,search: false
                    ,click: function(obj){
                        //console.log(obj)
                    }
                    ,ready: function(){
                        //console.log(1)
                    }});

                form.on('submit(menu-save)', function(data){
                    data.field.state = data.field.state == "on" ? 1 : 0;
                    data.field.icon = "layui-icon " + data.field.icon;
                    if(data.field.parent != -1){
                        data.field.type=1;
                        data.field.openType=0;
                    }else{
                        data.field.type=0;
                    }
                    $.ajax({
                        url: MODULE_PATH + 'data/save',
                        data:JSON.stringify(data.field),
                        dataType:'json',
                        contentType:'application/json',
                        type:'post',
                        success:function(result){
                            if(result.code == 0){
                                layer.msg(result.message,{icon:1,time:1000},function(){
                                    parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                                    parent.layui.table.reload("menu-table");
                                });
                            }else{
                                layer.msg(result.message,{icon:2,time:1000});
                            }
                        }
                    })
                    return false;
                });
            })
        </script>
        <script>
        </script>
    </body>
</html>